<?php
require_once("config.php");
require_once 'wappay/service/AlipayTradeService.php';
kgLog(json_encode($_POST));

$arr=$_POST;
$alipaySevice = new AlipayTradeService($config); 
$alipaySevice->writeLog(var_export($_POST,true));
$result = $alipaySevice->check($arr);
 $orderId= $_POST['out_trade_no'];
	$total_fee= $_POST['total_amount']; 
if($result) {//验证成功
   
    kgLog("orderId:".$orderId."notify verify ok");
	kgLog("orderId:".$orderId);
	kgLog("total_fee:".$total_fee);    
	echo "success";		//请不要修改或删除
  	if($_POST['trade_status']=="TRADE_SUCCESS"){
		$data['out_trade_no']=$orderId;
		$data['total_fee']=$total_fee;
       kgLog("sucess:".var_export($data,true));
	   $url="http://888.liluyang.cn/index.php/pay/respon/init";
	  $res=postXmlCurl(json_encode((object)$data), $url);
     
        kgLog("trade success2:".$res);
	}
		
}else {
    kgLog("orderId:".$orderId."notify verify faile");
    //验证失败
    echo "fail";	//请不要修改或删除

}
function kgLog($msg){
		$filename = "notifylog".date('Y-m-d')."log.txt";
		$file = fopen($filename,'a');
		$msg = '['.date('Y-m-d H:i:s').'] '.$msg."\r\n";
		fwrite($file, $msg, 4096);
		fclose($file);
	}
	
	 function postXmlCurl($xml, $url, $second = 30)
    {
        $ch = curl_init();
        //设置超时
        curl_setopt($ch, CURLOPT_TIMEOUT, $second);
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        //设置header
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        //post提交方式
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        //运行curl
        $data = curl_exec($ch);
        //返回结果
        if($data){
            curl_close($ch);
            return $data;
        } else {
            $error = curl_errno($ch);
            curl_close($ch);
            return $error;
        }
    }
	
?>

